import numpy as np
from scipy.fft import fft
from scipy.io import wavfile
from matplotlib.pyplot import specgram
from matplotlib import pyplot as plt


# samplerate, X = wavfile.read("G:/akaa/genres/blues/converted/blues.00000.au.wav")
# print(samplerate, X.shape)
#
# plt.figure(figsize=(10, 4), dpi=80)
# plt.xlabel("time")
# plt.ylabel("frequency")
# plt.grid(True, linestyle='-', alpha=0.75)
# specgram(X, Fs=samplerate, xextent=(0, 30))
# plt.show()
# plt.figure(num=None, figsize=(9, 6), dpi=80, facecolor='w', edgecolor='k')
# plt.subplot(2, 1, 1)
# plt.xlabel("time")
# plt.ylabel("frequency")
# specgram(X, Fs=samplerate, xextent=(0, 30))
#
# plt.subplot(2, 1, 2)
# plt.xlabel("frequency")
# plt.ylabel("amplitude")
# plt.xlim(3000)
# plt.plot(fft(X, samplerate))
#
# plt.show()

def create_fft(g, n):
    rad = f"G:/akaa/genres/{g}/converted/{g}.{str(n).zfill(5)}.au.wav"
    samplerate, X = wavfile.read(rad)
    fft_features = abs(fft(X)[:1000])
    sad = f"G:/akaa/genres/trainset/{g}.{str(n).zfill(5)}.fft"
    np.save(sad, fft_features)


genres_list = ['classical', 'jazz', 'country', 'pop', 'rock', 'metal']
for g in genres_list:
    for n in range(100):
        create_fft(g, n)
